﻿{extend name="public:base" /}


{block name="css"}
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css"/>
<link rel="stylesheet" type="text/css" href="__ADMIN__/css/style.css">

<style>
    layui-progress-big, .layui-progress-big .layui-progress-bar {
        height: 30px;
        line-height: 30px
    }

    .layui-progress {
        position: relative;
        height: 30px;
        border-radius: 20px;
        background-color: #eee;
    }

    .layui-progress-text {
        position: relative;
        top: -20px;
        line-height: 30px;
        font-size: 12px;
        color: #666;
    }

    .webuploader-pick {
        width: 120px;
        background: #1ab394;
        padding: 9px 0;
        font-size: 13px;
    }

    .webuploader-pick-hover {
        background: #19A689;
    }

</style>{/block}


{block name="content"}

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <form method="post">
                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">名称</label>
                                <div class="col-sm-3">
                                    <input type="text" required class="form-control" name="name" placeholder="请输入名称" value="{$info.name}">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row"><label class="col-sm-1 col-form-label">封面图</label>
                                <div class="col-sm-6">
                                    <input type="file" id="img_file" accept="image/*" style="display: none">
                                    <input type="hidden" class="hidden_value" name="img" id="img" value="{$info['img']|default=''}"/>
                                    <div class="btn btn-w-m btn-primary" onclick="uploadImage('img_file', 'img', 'form-uploaded-box-single', false, 1)">原图上传</div>
                                    <div class="btn btn-w-m btn-primary" onclick="openCrop('form-uploaded-box-single', 1)">裁剪上传</div>

                                    <div class="form-uploaded-box" id="form-uploaded-box-single" style="width: 140px">
                                        {if $info.img}
                                        <div class="form-uploaded-img-box">
                                            <img class="form-uploaded-box-img" src="{:getPicture($info.img)}" data-id="{$info.img}">
                                            <i class="form-uploaded-img-preview iconfont icon-yulan" onclick="previewImg(this, 'form-uploaded-img-preview')"></i>
                                            <i class="form-uploaded-img-del iconfont icon-close" onclick="delImage(this, 'cropper_uploaded_img_ids', 'cropper_uploaded_img_paths', 'form-')"></i>
                                        </div>
                                        {/if}
                                    </div>
                                </div>

                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row layui-form">
                                <label class="col-sm-1 col-form-label">所属省市</label>
                                <div class="col-sm-2">
                                    <select id="province" name="province_id" lay-filter="province">
                                        <option value="0">请选择省</option>
                                    </select>
                                </div>
                                <div class="col-sm-2">
                                    <select id="city" name="city_id" lay-filter="city">
                                        <option value="0">请选择市</option>
                                    </select>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">标签</label>
                                <div class="col-sm-3">
                                    <input type="text" required class="form-control" name="tags" placeholder="请输入名称" value="{$info.tags}">
                                    <span class="form-text m-b-none" style="color: red">多个标签英文逗号分隔</span>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="box-item">
                            <div class="row">
                                <label class="col-sm-1 col-form-label">简介</label>
                                <div class="col-lg-6">
                                    <div class="ibox">
                                        <textarea id="editor_id">{$info.des}</textarea>
                                        <textarea name="des" data-editor="kindEditor" style="display: none"></textarea>
                                    </div>
                                </div>
                            </div>

                            <div class="hr-line-dashed"></div>
                        </div>


                        <div class="form-group row">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button type="button" class="btn btn-w-m btn-default back-page">返回</button>
                                <button type="button" class="btn btn-w-m btn-primary ajax-post">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

{include file="public/cropper-img-mask" cropper_uploaded_img_ids="cropper_uploaded_img_ids" cropper_uploaded_img_paths="cropper_uploaded_img_paths" crop_preview_box="crop-preview-box" /}{include file="public/preview-img-mask" swiper-id="cropper-preview" /}{/block}

{block name='js'}
<script src="__STATIC__/layui/layui.js"></script>
<script type="text/javascript" src="__PLUG__/kindeditor/kindeditor-all.js"></script>
<script>
    var province_list = {$province_list_json},
      province_id = `{$info.province_id}` ? parseInt(`{$info.province_id}`) : 0,
      city_id = `{$info.city_id}` ? parseInt(`{$info.city_id}`) : 0;

    $(function () {
        initKindEditor('editor_id');

        renderRegion(province_list, province_id, city_id);

        layui.use('form', function () {
            var form = layui.form;

            form.on('select(province)', function (data) {
                var province_id = data.value;

                renderRegion(province_list, province_id);
            })
        })

    })

    function renderRegion(region_list, province_id = 0, city_id = 0) {
        layui.use('form', function () {
            var form = layui.form;

            var province_options = '<option value="0">请选择省</option>';
            var city_options = '';
            region_list.forEach(val => {
                province_options += `<option value="${val.province_id}" ${val.province_id == province_id ? 'selected' : ''}>${val.province_name}</option>`;
                if (val.province_id == province_id) {
                    val.city_list.forEach(v => {
                        city_options += `<option value="${v.city_id}" ${v.city_id == city_id ? 'selected' : ''}>${v.city_name}</option>`;
                    })
                }
            })

            $('#province').html(province_options);
            $('#city').html(city_options);

            form.render('select');
        })
    }

</script>{/block}
